package com.ruoyi.system.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.tree.ITree;
import com.ruoyi.system.domain.typehandler.CmdConfigTypeHandler;
import com.ruoyi.system.domain.vo.order.OrderConfig;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Transient;

import java.util.ArrayList;
import java.util.List;

/**
 * 指令配置对象 t_order_configuration
 * 
 * @author wp
 * @date 2023-08-10
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
@TableName(value = "t_order_configuration", autoResultMap = true, excludeProperty = {"createBy", "updateTime", "updateBy", "remark"})
public class OrderConfiguration extends com.ruoyi.common.core.domain.BaseEntity implements ITree<OrderConfiguration> {
    private static final long serialVersionUID = 1L;

    /** 唯一主键 */
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    /** 父id */
    @Excel(name = "父id")
    private Long parentId;

    /** 指令名称 */
    @Excel(name = "指令名称")
    private String orderName;

    /** 指令类型 */
    @Excel(name = "指令类型")
    private String orderType;

    /** 是否叶子节点  0：否 1：是 */
    @Excel(name = "是否叶子节点  0：否 1：是")
    private Long hasChild;

    /** 配置值 */
    @Excel(name = "配置值")
    @TableField(typeHandler = CmdConfigTypeHandler.class)
    private List<OrderConfig> confValue;

    /** 是否等待应答(0否1是) */
    @Excel(name = "是否等待应答(0否1是)")
    private Integer response;

    /** 是否为通用应答指令（0否1是） */
    @Excel(name = "是否为通用应答指令", readConverterExp = "0=否1是")
    private Integer isNormal;

    /** 子组织 */
    @TableField(exist = false)
    @Transient
    private List<OrderConfiguration> children = new ArrayList<>();

    @Override
    public String id() {
        return String.valueOf(id);
    }
    @Override
    public String parentId() {
        return String.valueOf(parentId);
    }
    @Override
    public void parentId(String parentId) {
        this.parentId = Long.parseLong(parentId);
    }

    @Override
    public Integer type() {
        return null;
    }

    @Override
    public String label() {
        return orderName;
    }

    @Override
    public String ancestors() {
        return null;
    }

    public List<OrderConfiguration> getChildren() {
        return children;
    }

    public void setChildren(List<OrderConfiguration> children) {
        this.children = children;
    }

    @Override
    public void childrenToEmpty() {
        children = new ArrayList<>();
    }
}
